package com.TT.controller;

import com.TT.common.REST.RESTResponse;
import com.TT.common.REST.ResCode;
import com.TT.domain.mysql.Room;
import com.TT.service.mysql.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.UUID;

/**
 * @author 苏文广 created at 2018/11/27
 * @Description: 房源信息服务
 */
@RestController
@Slf4j
@RequestMapping("/room")
public class RoomController extends BaseController {
    @Autowired
    RoomService roomService;

//    @RequestMapping(value = "/add", method = RequestMethod.POST)
////    @RecordLog(oprationName = "添加房源",level = Level.INFO_Level)
//    public RESTResponse add(@RequestBody @Validated Room room, BindingResult bindingResult) {
//
//        try {
//            String validate = validate(bindingResult);
//
//            room.setRoomId(UUID.randomUUID().toString());
//            if (!StringUtils.isBlank(validate)) {
//                return RESTResponse.msg_Fail(validate);
//            }
//            roomService.add(room);
//            return RESTResponse.simple_success();
//        } catch (Exception e) {
//            tryLog(e);
//            return RESTResponse.simple_fail();
//        }
//    }

//    @RequestMapping(value = "/delete",method = RequestMethod.POST)
//    public RESTResponse delete(@RequestBody Room room){
//        try{
//            roomService.delete(room);
//            return RESTResponse.simple_success();
//        }catch (Exception e){
//            tryLog(e);
//            return RESTResponse.simple_fail();
//        }
//    }
//    @RequestMapping(value = "/query",method = RequestMethod.GET)
//    public RESTResponse<List<Room>> query(){
//        try {
//            List<Room> rooms=roomService.query();
//            return new RESTResponse<>(ResCode.Simple_SUCESS,rooms);
//        }catch (Exception e){
//            tryLog(e);
//            return new RESTResponse<>(ResCode.Simple_FAIL, null);
//        }
//    }
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public RESTResponse update(@RequestBody Room room){
        try {
            roomService.update(room);
            return RESTResponse.simple_success();
        }catch (Exception e){
            tryLog(e);
            return RESTResponse.simple_fail();
        }
    }
}
